package person.bing.fbcloud.leetcode;

import java.util.Arrays;

/**
 * @author: mengfanbing
 * @date: 2020/8/17 11:10
 */
public class Q26 {
    public static void main(String[] args) {
        int nums[] = {1,1,2,3};
        int i = removeDuplicates(nums);
        System.out.println(i);
    }
    public static int removeDuplicates(int[] nums) {
        int length = nums.length;
        int ans = 1;
        for (int i=1;i<length;i++){
            if (nums[i] == nums[i-1]){
                for(int j=i+1;j<length;j++){
                    if(nums[j] != nums[i]){
                        nums[ans] = nums[j];
                        i = j;
                        ans++;
                        break;
                    }
                }
            }else {
                nums[ans] = nums[i];
                ans++;
            }
        }
        System.out.println(Arrays.toString(nums));
        return ans;
    }
}
